package com.fourth.service.impl;

import com.fourth.entity.CartItem;
import com.fourth.dao.CartItemMapper;
import com.fourth.service.CartItemService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CartItemServiceImpl implements CartItemService {

    @Resource
    private CartItemMapper cartItemMapper;

    /**
     * 根据uId获取所有的商品信息
     * @param uId
     * @return
     */
    @Override
    public List<CartItem> selectCartItemByUid(Integer uId) {

        List<CartItem> cartItems = cartItemMapper.selectCartItemByUid(uId);

        for (CartItem item : cartItems) {
            Integer num = item.getNum();
            Integer stockNum = item.getStockNum();
            if(num > stockNum){
                item.setCheck("没货");
            }else {
                item.setCheck("有货");
            }
        }
        return cartItems;
    }

    @Override
    public int updateStockNum(Integer num, Integer gid) {
        return cartItemMapper.updateStockNum(num,gid);
    }
}
